package net.prasenjit.poc.integration;

import net.prasenjit.poc.integration.model.BookOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Router;

/**
 * Created by PPurohit on 12/26/2014.
 */
@MessageEndpoint
public class OrderRouter {

    final Logger logger = LoggerFactory.getLogger(OrderRouter.class);

    /**
     * Process order.  Routes based on whether or
     * not the order is a delivery or pickup.
     */
    @Router(inputChannel="processOrder")
    public String processOrder(BookOrder order) {
        String result = null;

        logger.debug("In OrderRouter.  title='{}'  quantity={}  orderType={}",
                new Object[] { order.getTitle(),
                        order.getQuantity(),
                        order.getOrderType() });

        switch (order.getOrderType()) {
            case DELIVERY:
                result = "delivery";
                break;
            case PICKUP:
                result = "pickup";
                break;
        }

        System.out.println("Routed to " + result);

        return result;
    }

}
